package com.qf.service.impl;

import com.qf.api.CacheFegin;
import com.qf.constant.StrategyConstants;
import com.qf.dfa.SensitiveWordFilter;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import com.qf.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author dell
 * @version V1.0
 * @Date 2022/6/8 9:42:49
 */
@Service("dirtyWords")
@Slf4j
public class DirtyWordFilterServiceImpl implements FilterChainService {


    @Autowired
    private PushMsgUtil pushMsgUtil;
    /**
     * 敏感词过滤
     * @param standardSubmit
     * @return
     * @throws Exception
     */
    @Override
    public boolean strategy(StandardSubmit standardSubmit) throws Exception {
        log.info("开始敏感词策略");
        //获取短信内容
        String messageContent = standardSubmit.getMessageContent();
        //IK分词

        //redis中查询
        int count = SensitiveWordFilter.getInstance().checkSensitiveWord(messageContent, 0, SensitiveWordFilter.maxMatchType);
        //判断敏感词
        if(count==0){
            log.info("敏感词策略执行成功");
            return true;
        }else {
            log.error("存在敏感词");
            pushMsgUtil.sendLog(standardSubmit,StrategyConstants.STRATEGY_ERROR_DIRTY_WORDS);
            pushMsgUtil.pushReport(standardSubmit,StrategyConstants.STRATEGY_ERROR_DIRTY_WORDS);
            return false;
        }





    }


}
